package com.timschimandle.getitdone;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PersonAdapter extends ArrayAdapter<Person> {
	
	private Context c;
	private ArrayList<Person> people;
	
	public PersonAdapter(Context context, int textViewResourceId, ArrayList<Person> people) {
		super(context, textViewResourceId, people);
		// TODO Auto-generated constructor stub
		this.c = context;
		this.people = people;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
       
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.person_list_row, null);
            TextView tv = (TextView) v.findViewById(R.id.name);
            tv.setText(people.get(position).getFirstName() + " " + people.get(position).getLastName());
        } else {
        	TextView tv = (TextView) v.findViewById(R.id.name);
            tv.setText(people.get(position).getFirstName() + " " + people.get(position).getLastName());
        }
        return v;
    }

}
